class Solution {
public:
    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {
        
        sort(potions.begin(),potions.end());
        vector<int> vecRet;
        int n=spells.size(),m=potions.size();
        for(int i=0;i<n;++i){
            int left=0,right=m-1;
            while(left<right){
                int mid=left+(right-left)/2;
                if(static_cast<long long>(potions[mid])*spells[i]<success){
                    left=mid+1;
                }
                else{
                    right=mid;
                }
            }
            int pos=0;
            if(static_cast<long long>(potions[left])*spells[i]>=success){
                pos=m-left;
            }
            vecRet.push_back(pos);
        }

        return vecRet;
    }
};
